package com.aaa.service.scl.impl;

import com.aaa.dao.scl.ViewTestResultSclDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.scl.ViewTestResultScl;
import com.aaa.service.scl.ViewTestResultSclService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("viewTestResultSclService")
public class ViewTestResultSclServiceImpl implements ViewTestResultSclService {
    @Resource
    ViewTestResultSclDao viewTestResultSclDao;

    @Override
    public List<ViewTestResultScl> queryAllByCondition(PageSortEntity pageSortEntity, ViewTestResultScl viewTestResultScl) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit());
        List<ViewTestResultScl> viewTestResultSclList = viewTestResultSclDao.queryAllByCondition(viewTestResultScl);
        Page page = (Page) viewTestResultSclList;
        return page;
    }

    /**
     * 报表统计 查询
     * @return
     */
    @Override
    public Map<String, Integer> queryAll() {

        int a1=0;
        int a2=0;
        int a3=0;
        int a4=0;
        int a5=0;
        int a6=0;
        int a7=0;
        int a8=0;
        int a9=0;
        int a10=0;
        int sum=0;
        List<ViewTestResultScl> viewScls = viewTestResultSclDao.queryAll();
        for (ViewTestResultScl viewScl : viewScls) {
         double   f1 = viewScl.getF1();
         double   f2 = viewScl.getF2();
         double   f3 = viewScl.getF3();
         double   f4 = viewScl.getF4();
         double   f5 = viewScl.getF5();
         double   f6 = viewScl.getF6();
         double   f7 = viewScl.getF7();
         double   f8 = viewScl.getF8();
         double   f9 = viewScl.getF9();
         double   f10 = viewScl.getF10();
            if(f1>2.43){
                a1=a1+1;
            }
            if(f2>3.27){
                a2=a2+1;
            }
            if(f3>3.46){
                a3=a3+1;
            }
            if(f4>3.13){
                a4=a4+1;
            }
            if(f5>2.82){
                a5=a5+1;
            }
            if(f6>3.13){
                a6=a6+1;
            }
            if(f7>2.52){
                a7=a7+1;
            }
            if(f8>3.23){
                a8=a8+1;
            }
            if(f9>2.71){
                a9=a9+1;
            }
            if(f10>3.23){
                a10=a10+1;
            }
            if(f1!=0){
                sum++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("a1", a1);
        map.put("a2", a2);
        map.put("a3", a3);
        map.put("a4", a4);
        map.put("a5", a5);
        map.put("a6", a6);
        map.put("a7", a7);
        map.put("a8", a8);
        map.put("a9", a9);
        map.put("a10",a10);
        map.put("sum",sum);
        return map;
    }


    @Override
    public boolean deleteById(Integer id) {
        return this.viewTestResultSclDao.deleteById(id) > 0;
    }

    @Override
    public Integer delTestPlanBatch(int[] id) {
        return viewTestResultSclDao.delALLById(id);
    }


    @Override
    public ViewTestResultScl queryById(ViewTestResultScl viewTestResultScl) {
        return viewTestResultSclDao.queryById(viewTestResultScl);
    }
}
